package cn.itcast.order.web;

import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private OrderService orderService;



    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") int orderId,
                                    @RequestHeader(value = "name", required = false) String name) {
        System.out.println("order服务name: " + name);
        // 根据id查询订单并返回
        return orderService.TestSeataQueryOrderById(orderId);
    }

    @GetMapping("/TestSeataTCC/{orderId}/{num}")
    @GlobalTransactional
    public void TestSeataTCC(@PathVariable("orderId") int orderId,
                                    @PathVariable("num") int num) {
        System.out.println("order服务库存num: " + num);
        // 根据id查询订单并返回
        orderService.testSeataTCC(orderId, num);
    }
}
